package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoInsertFill;
import com.sky.annotation.AutoUpdatetFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * The type Dish mapper.
 */
@Mapper
public interface DishMapper {


    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId the category id
     * @return the boolean
     */
    @Select("select count(*) from dish where category_id = #{categoryId}")
    Long selectCountByCategoryId(@Param("categoryId") Long categoryId);


    /**
     * 查询个数
     *
     * @param dishDTO the dish dto
     * @return the integer
     */
    Integer selectCount(DishDTO dishDTO);


    /**
     * 增加并返回id
     *
     * @param dish the dish
     * @return the long
     */
    @AutoInsertFill
    void insert(Dish dish);


    /**
     * 分页查询
     *
     * @param dishPageQueryDTO the dish page query dto
     * @return the page
     */
    Page<DishVO> selectPage(DishPageQueryDTO dishPageQueryDTO);


    /**
     * 根据id批量删除
     *
     * @param ids the ids
     */
    void deleteByIds(List<Long> ids);


    /**
     * 根据id和状态查询个数
     *
     * @param ids    the ids
     * @param status the status
     * @return the integer
     */
    Integer selectCountByIdsAndStatus(List<Long> ids, Integer status);


    /**
     * 根据id查询
     *
     * @param id the id
     * @return the dish vo
     */
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user from dish where id = #{id}")
    DishVO selectById(Long id);


    /**
     * 根据id跟新
     *
     * @param dish the dish
     */
    @AutoUpdatetFill
    void updateById(Dish dish);

    /**
     * 根据分类id查询菜品
     *
     * @param dish the dish
     * @return the list
     */
    List<Dish> selectByCategoryId(Dish dish);


    /**
     * 根据菜品状态查询个数
     *
     * @param status    the disable
     * @param setmealId the setmeal id
     * @return the integer
     */
    Integer selectCountByStatus(Integer status, Long setmealId);

    /**
     * Update by status.
     *
     * @param status the status
     * @param id     the id
     */
    @Update("update dish set status = #{status}  where id = #{id}")
    void updateByStatus(Integer status, Long id);


}
